package com.example.xianji.receiver;

import com.example.xianji.constant.Constant;
import com.example.xianji.fragment.HomeFragment;
import com.example.xianji.utils.DownloadManagerUtils;
import com.example.xianji.utils.sp.PreferenceEngine;

import android.app.DownloadManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

/**
 * 下载APK包的广播接收
 * @author me
 *
 */
public class DownloadApkReceiver extends BroadcastReceiver {

    private static final String TAG = "DownloadApkReceiver";
    private static final int APK_EXIST = 1;

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) {
            DownloadManagerUtils.installApk(context.getApplicationContext());
            //再次打开直接安装 保存当前状态
            PreferenceEngine.getInstance().putInt(Constant.SP.NAME,Constant.SP.KEY_XIANJI_APK_EXIST,APK_EXIST);
//            context.getSharedPreferences("text", context.MODE_PRIVATE).edit()
//                    .putInt("Xianji_APK_EXIST", APK_EXIST).commit();
            /**********************表明已经下载完成**********************/
            HomeFragment.isLoadingAPk=false;
        } else if (intent.getAction().equals(DownloadManager.ACTION_NOTIFICATION_CLICKED)) {
        }
    }
}
